package com.crm.biz.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.crm.model.BizExamSetting;
import com.crm.service.BizExamSettingService;
import com.crm.util.JsonUtil;
import com.crm.util.ResponseUtil;
import com.github.pagehelper.Page;

@Controller
@RequestMapping("/bizExamSetting")
public class BizExamSettingController {
	@Autowired
	private BizExamSettingService bizExamSettingService;
	
	@RequestMapping("/index")
	public String index(){
		return "configuration/examSittings";
	}
	
	@RequestMapping("/getAll")
	@ResponseBody
	public Map<String, Object> getAll(Page<BizExamSetting> page, BizExamSetting t){
		Map<String, Object> map = new HashMap<>();
		Page<BizExamSetting> list = (Page<BizExamSetting>) bizExamSettingService.selectAll(page, t);
		
		map.put("list", list);
		map.put("status", "success");
		map.put("msg", "查询成功！");
		
		return map;
	}
	
	@RequestMapping("/addNewRecord")
	@ResponseBody
	public Map<String, Object> addNewRecord(BizExamSetting record){
		
		Map<String, Object> map = new HashMap<>();
		
		bizExamSettingService.insert(record);
		
		map.put("status", "success");
		map.put("msg", "新增成功！");
		
		return map;
	}
	
	@RequestMapping("/updateRecord")
	@ResponseBody
	public Map<String, Object> updateRecord(BizExamSetting record){
		
		Map<String, Object> map = new HashMap<>();
		
		bizExamSettingService.updateByPrimaryKey(record);
		
		map.put("status", "success");
		map.put("msg", "修改成功！");
		
		return map;
	}
	
	@RequestMapping("/load")
	@ResponseBody
	public void load(HttpServletResponse response,HttpServletRequest request, Page<BizExamSetting> page, BizExamSetting t){
		Page<BizExamSetting> list = (Page<BizExamSetting>) bizExamSettingService.selectAll(page, t);
		ResponseUtil.resultPage(response,request,list);
	}
	
	/**
	 * 
	 * @Description : 异步获取考期
	 * @author zealot
	 * @param @param response
	 * @param @param request
	 * @param @param t
	 * @return void
	 * @version 创建时间 : 2016年12月5日 下午1:48:36
	 * @thorws
	 */
	@RequestMapping("/ajaxLoad")
	@ResponseBody
	public void ajaxLoad(HttpServletResponse response,HttpServletRequest request,BizExamSetting t){
		List<BizExamSetting> list =  bizExamSettingService.selectByUs(t);
		ResponseUtil.result(response,JsonUtil.toJsonStr(list));
	}
}
